package com.webcat.controller;

import com.webcat.entity.AiResponse;
import com.webcat.entity.Response;
import com.webcat.entity.SseResponse;
import com.webcat.service.ChatService;
import com.webcat.service.RagService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.document.Document;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequestMapping("/rag")
@Slf4j
public class RagController {

    @Resource
    private RagService ragService;


    @GetMapping(value = "/loadDocument")
    public Response<Void> loadDocument() {
        ragService.loadDocument();
        return Response.success();
    }

    @PostMapping(value = "/uploadFiles")
    public Response<Void> uploadFiles(@RequestParam("files") List<MultipartFile> files) {
        ragService.loadDocument(files);
        return Response.success();
    }

    @GetMapping(value = "/query")
    public Response<List<Document>> query(@RequestParam String text) {
        return Response.success(ragService.query(text));
    }
}
